<%--
  Created by IntelliJ IDEA.
  User: gongsir
  Date: 2019/8/21
  Time: 15:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    pageContext.setAttribute("path", request.getContextPath());
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加影片信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${path}/static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${path}/static/css/admin.css" media="all">
    <script type="text/javascript" src="${path}/static/layui/layui.js"></script>
</head>
<body>
<div class="layui-container layui-card">
    <div class="layui-fluid">
        <div class="layui-card-header">
            <h2>添加影片信息</h2>
        </div>
    </div>
    <div class="layui-fluid layui-card-body">
        <form class="layui-form" method="post" action="${path}/movie">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">影片名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" id="name" placeholder="请输入" required autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">导演</label>
                    <div class="layui-input-block">
                        <input type="text" name="director" id="director" placeholder="请输入" required autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">演员</label>
                    <div class="layui-input-block">
                        <input type="text" name="action" id="action" placeholder="请输入" required autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">发行地</label>
                    <div class="layui-input-block">
                        <select id="movieDistribution" name="distribution">
                            <option value="成都">成都</option>
                            <option value="北京">北京</option>
                            <option value="上海">上海</option>
                            <option value="广州">广州</option>
                            <option value="深圳">深圳</option>
                            <option value="杭州">杭州</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">上映时间</label>
                    <div class="layui-input-block">
                        <input type="text" name="date" id="movieDate" required autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">封面图片</label>
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn" id="uploadPic">
                            <i class="layui-icon">&#xe67c;</i>选择图片
                        </button>
                        <br>
<%--                        <button type="button" class="layui-btn layui-btn-warm" id="uploadPicBtn">开始上传</button>--%>
                        <input type="hidden" name="picUrl" id="picUrl" value="" class="layui-input">
                        <input type="text" disabled id="showPicUrl" value="回显url" class="layui-input">
<%--                        <div class="layui-upload-list">--%>
<%--                            <img class="layui-upload-img" width="100px" height="80px" id="preShow"/>--%>
<%--                            <p id="demoText"></p>　--%>
<%--                        </div>--%>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">影片链接</label>
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn" id="uploadVideo">
                            <i class="layui-icon">&#xe67c;</i>上传视频
                        </button>
                        <br>
                        <input type="text" disabled id="showMovieUrl" value="回显url" class="layui-input">
<%--                        <button type="button" class="layui-btn layui-btn-warm" id="uploadVideoBtn">开始上传</button>--%>
                        <input type="hidden" name="movieUrl" id="movieUrl" class="layui-input" value="">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">上映状态</label>
                    <div class="layui-input-block">
                        <select id="status" name="status">
                            <option value="true">立即上映</option>
                            <option value="false">暂不上映</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-col-md-offset1">
                <div class="layui-input-inline">
                    <input type="submit" id="btn_editImg" class="layui-btn layui-btn-fluid" value="提交">
                </div>
            </div>
            <div class="layui-form-item layui-col-md-offset1">
                <div class="layui-input-inline">
                    <button type="button" id="btn_goBack" class="layui-btn layui-btn-fluid" onclick="goBack()">返回</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use('upload', function () {
        var upload = layui.upload,
            $ = layui.jquery,
            layer = layui.layer;
        //上传图片
        var uploadInst = upload.render({
            elem: '#uploadPic' //绑定元素
            , url: '${path}/upload' //上传接口 [[@{/upload/img}]]
            , auto: true
            // , bindAction: '#uploadPicBtn'
            // , before: function (obj) {
            //     //预读本地文件示例，不支持ie8
            //     obj.preview(function (index, file, result) {
            //         $('#preShow').attr('src', result); //图片链接（base64）
            //     });
            // }
            , choose: function () {
                layer.msg("后台正在上传文件,请稍等...",{icon:1,time:3000});
            }
            , done: function (res) {
                //如果上传失败
                if (res.code == 0) {
                    return layer.alert("上传失败:" + res.data.msg);
                }
                //上传成功
                document.getElementById("picUrl").value = res.data.url;
                document.getElementById("showPicUrl").value = res.data.url;
                return layer.msg('上传成功');
            }
            , error: function () {
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });

        //上传视频
        var uploadInst = upload.render({
            elem: '#uploadVideo'
            , url: '${path }/upload'
            , accept: 'video' //视频
            , auto: true
            , choose: function () {
                layer.msg("后台正在上传文件,请稍等...",{icon:1,time:2000});
            }
            , done: function (res) {
                console.log(res)
                //如果上传失败
                if (res.code == 0) {
                    return layer.alert('上传失败:'+res.data.msg);
                }
                //上传成功
                // alert("上传成功" + res.data.url);
                document.getElementById("movieUrl").value = res.data.url;
                document.getElementById("showMovieUrl").value = res.data.url;
                return layer.msg('上传成功');
            }
        });
    });
</script>
<script type="text/javascript">
    layui.use(['form', 'laydate'], function () {
        var $ = layui.$,
            form = layui.form,
            laydate = layui.laydate;
        laydate.render({
            elem: '#movieDate',
            format: 'yyyy-MM-dd'
        });
        form.render();
    });

    // 返回上一页
    function goBack() {
        window.history.go(-1);
    }
</script>
</body>
</html>
